package com.koron.common.core.interceptor;

import org.springframework.util.Assert;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Adapter命名规则：驼峰字段+Adapter
 * 如：create_time -> CreateTimeAdapter
 * @author jzp
 * @since 2021/9/26
 */
public class Adapters {

    private static final Map<String, FieldAdapter> fieldAdapterMap = new ConcurrentHashMap<>();

    private Adapters() {
        throw new IllegalStateException("Utility class");
    }

    public static FieldAdapter get(String field) {
        return fieldAdapterMap.get(field);
    }

    public static void register(String field, FieldAdapter adapter) {
        Assert.isNull(fieldAdapterMap.get(field), "字段 " + field + "已被注册");
        fieldAdapterMap.put(field, adapter);
    }

}
